import axios from "../index"; // 确保这里正确引入了 axios 库

interface EmailRequest {
  parentEmail: string;
  studentName: string;
  testName: string;
  score: string | number;
  testDate: string;
  teacherMessage: string;
}

interface Exam {
  examId: string;
  examName: string;
  examDate: string;
  // 其他考试相关属性
}

interface ExamRequest {
  name: string;
  startTime: string; //  ISO8601 格式字符串
  endTime: string;   //  ISO8601 格式字符串
  description: string;
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  questions: any[];
  }  //  直接使用 any 类型处理前端传递的题目数据

const URLs = {
  getExamAndParentInfo: '/examInfo',
  sendMessage: '/send-message', // 添加发送邮件的接口地址
  getExams: '/examApi/exams', // 添加获取考试列表的接口地址
  getQuestions: '/examApi/questions', // 添加获取考试列表的接口地址
  publishExam: '/examApi/exams/publish', // 添加发布考试接口地址
}

export const teacherApi = {
  // 获取考试和家长信息
  getExamAndParentInfo: async () => {
    return axios.get(URLs.getExamAndParentInfo);
  },

  // 发送邮件接口
  sendMessage: async (emailRequest: EmailRequest) => { // 明确指定参数类型
    return axios.post(URLs.sendMessage, emailRequest);
  },

  // 获取考试列表
  getExams: async () => {
    try {
      const response = await axios.get(URLs.getExams);
      return response;
    } catch (error) {
      console.error('获取考试列表失败:', error);
      throw error;
    }
  },

  // 示例：更新考试信息
  updateExam: async (examId: string, updatedExam: Exam) => {
    try {
      const response = await axios.put(`/exams/${examId}`, updatedExam);
      return response.data;
    } catch (error) {
      console.error('更新考试信息失败:', error);
      throw error;
    }
  },

  // 获取题目列表
  getQuestions: async () => {
    try {
      const response = await axios.get(URLs.getQuestions);
      return response;
    } catch (error) {
      console.error('获取题目列表失败:', error);
      throw error;
    }
  },

  // 发布考试
  publishExam: async (examRequest: ExamRequest) => {
    try {
      const response = await axios.post(URLs.publishExam, examRequest);
      return response;
    } catch (error) {
      console.error('发布考试失败:', error);
      throw error;
    }
  }
};
